$(window).on('load', function () {
    getRealtyData();
});

/**
 *请求房地产开发投资数据
 * */
var getRealtyData = function () {
    SGIS.API.post("macro/get/realty").data({'year':2018}).json(function (re) {
        if(re){
            var data = re.data;
            var name = re.name;
            var unit = re.unit;
            var xAxis_data = [],data_val = [];
            for(var i = 0 ; i < data.length ; i++){
                var item_x = data[i][1]+"-"+data[i][2];
                xAxis_data.push(item_x);
                data_val.push(data[i][0])
            }
            renderRealty_line(xAxis_data,data_val,unit,name);
        }else{
            return;
        }
    });

}
/**
 *绘制折现图
 * */
var myChart_line='';
var renderRealty_line = function (xAxis_data,data_val,unit,name) {
    var dom = document.getElementById("scatter-map-line-1");
    if(myChart_line){
        myChart_line.dispose()
    }
     myChart_line = echarts.init(dom);

    var option = {
        tooltip: {
            trigger: 'axis',
            formatter: "{a} <br/>{b}: {c}"+unit
        },
        legend: {
            data:[name]
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: xAxis_data
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name:name,
                type:'line',
                connectNulls:true,
                color: "#01baaf",
                data:data_val
            }
        ]
    };
    if (option && typeof option === "object") {
        myChart_line.setOption(option, true);
    }
}
